package com.distribution.system.controller;

import com.distribution.system.utils.TwoDimensionalCodeUtil;
import com.google.zxing.WriterException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Liping Huo
 * @date 2023/5/22 21:10
 */
@Controller
@RequestMapping(("/tool"))
public class CmccDaTwoDimensionalCodeController {

    @GetMapping("/QRCode")
    void getLinkTwoDimensionalCode(HttpServletRequest request, HttpServletResponse response) {
        String path = request.getParameter("codeLink");
        ServletOutputStream outputStream;
        try {
            outputStream = response.getOutputStream();
            TwoDimensionalCodeUtil.getTwoDimensionalCodeImageToStream(path, 500, 500, outputStream);
        } catch (IOException | WriterException e) {
            e.printStackTrace();
        }
    }
}
